﻿using habbo.Habbo.Catalog;
using habbo.Kernel.Packets.Messages;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace habbo.Kernel.Packets.com.sulake.habbo.communication.messages.outgoing.catalogue
{
    class CatalogIndexMessageComposer : ServerPacket
    {
        public CatalogIndexMessageComposer()
            : base(Headers.MessageComposerIds.CatalogIndexMessageComposer)
        {
            base.Append(true);
            base.Append(0);
            base.Append(0);
            base.Append(-1);
            base.Append("root");
            base.Append(false);
            base.Append(false);

            base.Append(SystemApp.HabboSystem.CatalogManager.GetPages().Count); //Count of pages

            foreach (CatalogPage Page in SystemApp.HabboSystem.CatalogManager.GetPages())
            {
                base.Append(Page.Visible);
                base.Append(Page.IconColor);
                base.Append(Page.IconImage);
                base.Append(Page.Id);
                base.Append(Page.Caption.ToLower().Replace(' ', '_'));
                base.Append(Page.Caption);
                base.Append(SystemApp.HabboSystem.CatalogManager.GetSubPages(Page.Id).Count);

                foreach (CatalogPage subPage in SystemApp.HabboSystem.CatalogManager.GetSubPages(Page.Id))
                {
                    base.Append(Page.Visible);
                    base.Append(subPage.IconColor);
                    base.Append(subPage.IconImage);
                    base.Append(subPage.Id);
                    base.Append(subPage.Caption.ToLower().Replace(' ', '_'));
                    base.Append(subPage.Caption);
                    base.Append(0);
                }
            }

            base.Append(true);
        }
    }
}
